<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

namespace Admin\Controller;
use Think\Controller;
class DialogController extends IndexController {
	
	//列表动作-----------------------------------------------------------------------------------------------
	public function indexAction(){
		
		$model=new \Admin\Model\MemberDialogModel();
		foreach($model->IndexGetData(
				//排序
				array(
					array('order'=>'id','name'=>'ID'),
					array('order'=>'fromuid','name'=>'发信人UID'),
					array('order'=>'touid','name'=>'收信人UID'),
					array('order'=>'toname','name'=>'收信人名称'),
					array('order'=>'lastmessage','name'=>'最后发表内容'),
					array('order'=>'dateline','name'=>'发布时间')
				),
				//查询
				array(	
					'id'=>array('id','int'),
					'fromuid'=>array('fromuid','int'),
					'touid'=>array('touid','int')
				)
				
			) as $key=>$value){
			$this->assign($key,$value);
		}

		$this->display();
	}
	
	//清空数据动作-----------------------------------------------------------------------------------------------
	public function clearAction(){
		
		$nowtime=NowTime()-(31*24*60*60);

		$dialogarr=M('MemberDialog')->token(false)->where(" dateline<'$nowtime' ")->select();
		if(!empty($dialogarr)){
			foreach($dialogarr as $dialog){
				$aid=intval($dialog['activity']);
				//删除全部
				M('MemberDialogMessage')->token(false)->where(" aid=$aid ")->delete();
				M('MemberDialog')->token(false)->where(" activity=$aid ")->delete();
			}
		}
		
		$this->error('删除成功!',U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
	}
	
	//删除动作-----------------------------------------------------------------------------------------------
	public function deleteAction(){
		
		$ids=GetCheckBox($_POST['checkbox']);
		
		if(!$ids){
			$ids=intval($_GET['id']);
		}
		
		if(!$ids){
			$this->error('对不起，请选择ID操作!',U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
		}	

		if($ids){
			//对方是否已删除
			$dialogarr=M('MemberDialog')->token(false)->where(" id IN($ids) ")->select();
			if(!empty($dialogarr)){
				foreach($dialogarr as $dialog){
					$aid=intval($dialog['activity']);
					//删除全部
					M('MemberDialogMessage')->token(false)->where(" aid=$aid ")->delete();
					M('MemberDialog')->token(false)->where(" activity=$aid ")->delete();
				}
			}
	
		}
		
		$this->error('删除成功!',U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
	}
	
}